package cn.com.css.taxInspection.common.job.task;



import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;

import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.gt3.entity.JcAjxxEntity;
import cn.com.css.taxInspection.gt3.entity.JcLsfxMxEntity;
import cn.com.css.taxInspection.gt3.service.JcAjxxService;
import cn.com.css.taxInspection.gt3.service.JcLsfxMxService;
import cn.com.css.taxInspection.gt3.service.JcSjlService;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workflow.service.WorkflowInspectionHearService;
import cn.com.css.taxInspection.workrisk.entity.WorkriskControlEntity;
import cn.com.css.taxInspection.workrisk.entity.WorkriskRisk1Entity;
import cn.com.css.taxInspection.workrisk.service.WorkriskControlService;
import cn.com.css.taxInspection.workrisk.service.WorkriskRisk1Service;

/**
 * 案件立案第27天提示检查人尽快做卷报审核；连续提醒三天 （督办）。
 *
 * @author shaochangyang
 * @version V1.0
 * @date 2020年3月18日
 */
@Component("risk1Task1")
public class Risk1Task1 {
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Resource
	private WorkflowInspectionHearService workflowInspectionHearService;
	
	@Resource
	private WorkriskRisk1Service workriskRisk1Service;
	
	@Resource
	private WorkriskControlService workriskControlService;
	
	@Resource
	private JcLsfxMxService jcLsfxMxService;
	
	@Resource
	private JcAjxxService jcAjxxService;
	
	public void run(String params) {
		logger.debug("risk1Task1定时任务正在执行，参数为：{}", params);
		Date date = new Date();
		List<JcLsfxMxEntity> list = jcLsfxMxService.getListAll();
		
		for (JcLsfxMxEntity jcLsfxMxEntity : list) {
			String ts = jcLsfxMxEntity.getTs();
			if(TsBqUtils.isNotNull(ts)){
				int _i = Integer.parseInt(ts);
				if(_i >= 27 && _i < 29){
					String relevance = jcLsfxMxEntity.getRelevance();
					JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
					String jcry = jcAjxxEntity.getJcry();
					WorkriskRisk1Entity workriskRisk1Entity = new WorkriskRisk1Entity();
					workriskRisk1Entity.setId(TsBqUtils.getUUID());
					workriskRisk1Entity.setRelevance(jcAjxxEntity.getJcajxxuuid());
					// workriskRisk1Entity.setStateCode(stateCode);
					// workriskRisk1Entity.setStateName();
					workriskRisk1Entity.setRiskType("1");
					workriskRisk1Entity.setRiskName("提醒");
					workriskRisk1Entity.setRiskMan1(jcry);
					workriskRisk1Entity.setDetails("案件立案第27天提示检查人尽快做卷报审核；连续提醒三天");
					workriskRisk1Entity.setTaxorgcode(jcAjxxEntity.getJcbmDm());
					workriskRisk1Entity.setDeleted(Constants.DATA_NOT_DELETED);
					workriskRisk1Entity.setCreateTime(new Date());
					workriskRisk1Entity.setCreateId("sysJob");
					workriskRisk1Service.save(workriskRisk1Entity);
					
				}else if(_i >= 30 && _i < 40){
					String relevance = jcLsfxMxEntity.getRelevance();
					JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
					String jcry = jcAjxxEntity.getJcry();
					WorkriskControlEntity workriskControlEntity = new WorkriskControlEntity();
					workriskControlEntity.setId(TsBqUtils.getUUID());
					workriskControlEntity.setRelevance(relevance);
					// workriskControlEntity.setStateCode();
					// workriskControlEntity.setStateName();
					workriskControlEntity.setControlType("1");
					workriskControlEntity.setControlName("督办");
					workriskControlEntity.setControlMan1(jcry);
					workriskControlEntity.setDetails("案件立案第30以上天督办流程");
					workriskControlEntity.setTaxorgcode(jcAjxxEntity.getJcbmDm());
					workriskControlEntity.setDeleted(Constants.DATA_NOT_DELETED);
					workriskControlEntity.setCreateTime(date);
					workriskControlEntity.setCreateId("sysJob");
					workriskControlService.save(workriskControlEntity);
					
				}else if(_i >= 40 && _i <= 60){
					String relevance = jcLsfxMxEntity.getRelevance();
					JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
					String jcry = jcAjxxEntity.getJcry();
					WorkriskControlEntity workriskControlEntity = new WorkriskControlEntity();
					workriskControlEntity.setId(TsBqUtils.getUUID());
					workriskControlEntity.setRelevance(relevance);
					// workriskControlEntity.setStateCode();
					// workriskControlEntity.setStateName();
					workriskControlEntity.setControlType("1");
					workriskControlEntity.setControlName("督办");
					workriskControlEntity.setControlMan1(jcry);
					workriskControlEntity.setDetails("案件立案第40以上天督办流程");
					workriskControlEntity.setTaxorgcode(jcAjxxEntity.getJcbmDm());
					workriskControlEntity.setDeleted(Constants.DATA_NOT_DELETED);
					workriskControlEntity.setCreateTime(new Date());
					workriskControlEntity.setCreateId("sysJob");

					workriskControlService.save(workriskControlEntity);
					
				}else if(_i > 60){
					String relevance = jcLsfxMxEntity.getRelevance();
					JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
					
					String jcry = jcAjxxEntity.getJcry();
					
					WorkriskControlEntity workriskControlEntity = new WorkriskControlEntity();
					
					workriskControlEntity.setId(TsBqUtils.getUUID());
					workriskControlEntity.setRelevance(relevance);

					// workriskControlEntity.setStateCode();

					// workriskControlEntity.setStateName();

					workriskControlEntity.setControlType("1");

					workriskControlEntity.setControlName("督办");

					workriskControlEntity.setControlMan1(jcry);
					workriskControlEntity.setDetails("案件立案第40以上天督办流程");

					workriskControlEntity.setTaxorgcode(jcAjxxEntity.getJcbmDm());
					
					workriskControlEntity.setDeleted(Constants.DATA_NOT_DELETED);
					workriskControlEntity.setCreateTime(new Date());
					workriskControlEntity.setCreateId("sysJob");

					workriskControlService.save(workriskControlEntity);
					
				}
			}
		}
		
		
	}

}
